package com.siam.package_rider.mapper;

import java.math.BigDecimal;
import java.util.Date;
import java.util.List;
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.siam.package_merchant.model.param.MerchantBillingRecordParam;
import com.siam.package_user.model.dto.MemberBillingRecordDto;
import org.apache.ibatis.annotations.Param;

import com.siam.package_rider.entity.TbRiderBill;
import com.siam.package_rider.model.param.TbRiderBillParam;
import org.apache.ibatis.annotations.Select;

/**
 * ---------------------------
 * 骑手账单表 (TbRiderBillMapper)         
 * ---------------------------
 * 作者：  高品
 * 时间：  2025-03-29 18:55:18
 * ---------------------------
 */
public interface TbRiderBillMapper extends BaseMapper<TbRiderBill> {

    /**
     * 基础分页查询
     * @param param
     * @return
     */    
    Page<TbRiderBill> page(@Param("page") Page page, @Param("param") TbRiderBillParam param);

    @Select("<script>select IFNULL(sum(mbr.number), 0) from tb_rider_bill mbr " +
            "<where> 1=1 and operate_type = 1 " +
            "<if test=\"riderBill.id != null\"> AND mbr.id = #{riderBill.id} </if>" +
            "<if test=\"riderBill.riderId != null\"> AND mbr.rider_id = #{riderBill.riderId} </if>" +
            "<if test=\"riderBill.type != null\"> AND mbr.type = #{riderBill.type} </if>" +
            "<if test=\"riderBill.operateType != null\"> AND mbr.operate_type = #{riderBill.operateType} </if>" +
            "<if test=\"riderBill.coinType != null\"> AND mbr.coin_type = #{riderBill.coinType} </if>" +
            "<if test=\"riderBill.number != null\"> AND mbr.number = #{riderBill.number} </if>" +
            "<if test=\"riderBill.message != null and riderBill.message != ''\"> AND mbr.message like '%${riderBill.message}%' </if>" +
            "<if test=\"riderBill.startCreateTime != null\"> AND DATE_FORMAT(mbr.create_time, '%Y/%m/%d') &gt;= #{riderBill.startCreateTime} </if>" +
            "<if test=\"riderBill.endCreateTime != null\"> AND DATE_FORMAT(mbr.create_time, '%Y/%m/%d') &lt;= #{riderBill.endCreateTime} </if>" +
            "</where> order by mbr.id desc" +
            "</script>")
    BigDecimal statisticalAmountByIncome(@Param("riderBill") TbRiderBillParam riderBill);

    @Select("<script>select IFNULL(sum(mbr.number), 0) from tb_rider_bill mbr " +
            "<where> 1=1 and operate_type = 2 " +
            "<if test=\"riderBill.id != null\"> AND mbr.id = #{riderBill.id} </if>" +
            "<if test=\"riderBill.riderId != null\"> AND mbr.rider_id = #{riderBill.riderId} </if>" +
            "<if test=\"riderBill.type != null\"> AND mbr.type = #{riderBill.type} </if>" +
            "<if test=\"riderBill.operateType != null\"> AND mbr.operate_type = #{riderBill.operateType} </if>" +
            "<if test=\"riderBill.coinType != null\"> AND mbr.coin_type = #{riderBill.coinType} </if>" +
            "<if test=\"riderBill.number != null\"> AND mbr.number = #{riderBill.number} </if>" +
            "<if test=\"riderBill.message != null and riderBill.message != ''\"> AND mbr.message like '%${riderBill.message}%' </if>" +
            "<if test=\"riderBill.startCreateTime != null\"> AND DATE_FORMAT(mbr.create_time, '%Y/%m/%d') &gt;= #{riderBill.startCreateTime} </if>" +
            "<if test=\"riderBill.endCreateTime != null\"> AND DATE_FORMAT(mbr.create_time, '%Y/%m/%d') &lt;= #{riderBill.endCreateTime} </if>" +
            "</where> order by mbr.id desc" +
            "</script>")
    BigDecimal statisticalAmountByExpend(@Param("riderBill") TbRiderBillParam riderBill);

    @Select("<script>select IFNULL(sum(m.number), 0) from tb_rider_bill as m "+
            "<where> 1=1 and (m.create_time between #{startTime} and #{endTime})" +
            "<if test=\"param.riderId != null\"> AND m.rider_id = #{param.riderId} </if>" +
            "<if test=\"param.typeList != null\"> and type in <foreach collection=\"param.typeList\" item=\"item\" index=\"index\" open=\"(\" separator=\",\" close=\")\">#{item}</foreach> </if>" +
            "<if test=\"param.operateType != null\"> AND m.operate_type = #{param.operateType} </if>" +
            "<if test=\"param.coinType != null\"> AND m.coin_type = #{param.coinType} </if>" +
            "</where>"+
            "</script>")
    BigDecimal selectSumNumber(@Param("param") TbRiderBillParam param, @Param("startTime") Date startTime, @Param("endTime") Date endTime);
}